// Author	: damphat@gmail.com
// Created	: 01/12/2008

#pragma once
#include "vn/IOCommon.h"

IO_BEGIN

class Path {
private:
	static void
	CheckInvalidPathChars(String path) {
		for (size_t i = 0; i < path.GetLength(); i++) {
			TChar c = path[i];
			if (((c == 0x22) || (c == 60)) || (((c == 0x3e) || (c == 0x7c)) || (c < 0x20))) {
				throw ArgumentException("Invalid path chars");
			}
		}
	}

public:
	static String
	GetFileName(String path) {
		CheckInvalidPathChars(path);
		size_t length = path.GetLength();
		size_t i = length;
		while (--i >= 0) {
			TChar ch = path[i];
			if (((ch == '\\') || (ch == '/')) || (ch == ':')) {
				return path.Substring(i + 1, (length - i) - 1);
			}
		}
		return path;
	}
};

IO_END

